package org.springframework.aop.framework.adapter;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

import org.springframework.aop.AfterAdvice;
import org.springframework.aop.AfterReturningAdvice;

/**
 * 后置增强拦截器
 *
 * @author zqc
 * @date 2022/12/20
 */
//不光是方法拦截器，而且定义为后置的
public class AfterReturningAdviceInterceptor implements MethodInterceptor, AfterAdvice {

	private AfterReturningAdvice advice;

	public AfterReturningAdviceInterceptor() {
	}

	public AfterReturningAdviceInterceptor(AfterReturningAdvice advice) {
		this.advice = advice;
	}

	//4.第四步！！！MethodInterceptor拦截器内部方法
	@Override
	public Object invoke(MethodInvocation mi) throws Throwable {
		//这是后置的方法，肯定和后置和前置具体实现方法有关
		//我们需要对照前置看

		Object retVal = mi.proceed();//原本方法，我们后置方法，先执行proceed（继续方法），再次进入做判断
		this.advice.afterReturning(retVal, mi.getMethod(), mi.getArguments(), mi.getThis());//后置方法
		return retVal;
	}
}
